import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

class JsonData {
    private String userId;
    private String classId;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getClassId() {
        return classId;
    }

    public void setClassId(String classId) {
        this.classId = classId;
    }
}


@WebServlet("/homework2")
public class HomeworkServlet2 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=utf8");
        String body = readBody(req);
        ObjectMapper objectMapper = new ObjectMapper();
        JsonData jsonData = objectMapper.readValue(body, JsonData.class);
        System.out.println("userId = " + jsonData.getUserId() + ", classId = " + jsonData.getClassId());
        resp.getWriter().write("userId = " + jsonData.getUserId() + ", classId = " + jsonData.getClassId());
    }
    private String readBody(HttpServletRequest req) throws IOException {
        byte[] buffer = new byte[req.getContentLength()];
        ServletInputStream inputStream = req.getInputStream();
        inputStream.read(buffer);
        return new String(buffer, "UTF-8");
    }
}
